/**
 * Created by Spring on 12/12/2017.
 */
({
  getAccount:function(cmp,accIdList){
    //拿到后台的方法
    var action = cmp.get("c.getAccountByIds");
    //设置参数  key-value 方式
    action.setParams({"accIdList":accIdList});
    //回调
    action.setCallback(this, function (response) {
      var state = response.getState();
      if (cmp.isValid() && state === "SUCCESS") {
        var accList = response.getReturnValue();
        console.log(accList);
        cmp.set("v.accList",accList);
        var sumCount = 0;
        for(var i = 0;i<accList.length;i++){
          sumCount += accList[i].NumberOfEmployees == null?0:accList[i].NumberOfEmployees;
        }
        console.log(sumCount);
        cmp.set("v.sumAmount", sumCount);
        this.rfDashBoard(cmp, sumCount);
      }
      //这里一定需要处理异常,提示用户,比如当长时间没有刷新界面,会话可能过期
    })
    //将当前操作放入到队列中,Aura框架会统一执行
    $A.enqueueAction(action);
  },

  //公共方法
  rfDashBoard:function(cmp,sumCount){
    var chartObj = cmp.get("v.myChart");
    console.log(chartObj)
    var   settings = {
        tooltip : {
            formatter: "{a} <br/>{b} : {c}%"
        },
        toolbox: {
            feature: {
                restore: {},
                saveAsImage: {}
            }
        },
        series: [
            {
                name: '员工数',
                type: 'gauge',
                detail: {formatter:'{value}%'},
                data: [{value: sumCount, name: '员工数'}]
            }
        ]
    };
    chartObj.setOption(settings, true);
  }
})